const browser = require('../browser');
const { logger } = require('../../utils/logger');

class PlaywrightForm {
  static async fillForm(url, formData, options = {}) {
    return browser.runWithPlaywright(url, options, async (page) => {
      for (const [selector, value] of Object.entries(formData)) {
        await page.waitForSelector(selector);
        await page.fill(selector, value);
      }
      
      logger.info(`Playwright表单填写成功: ${url}`);
      
      return {
        success: true,
        url,
        formData,
        timestamp: new Date().toISOString()
      };
    });
  }
}

module.exports = PlaywrightForm;
